<?php
/**
 * Created by PhpStorm.
 * User: LinMin
 * Date: 2018/1/31
 * Time: 16:04
 */

namespace App;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

class Config
{
    public static function get($cf_name){
        $cf=DB::table('config')->select('cf_value')->where('cf_name',$cf_name)->get();
        return $cf;
    }
    public static function set($cf_name,$cf_value,$only=false){
        if($only)
        {
            DB::beginTransaction();
            try{

                DB::table('config')->where('cf_name',$cf_name)->delete();
                $id = DB::table('config')->insertGetId(
                    ['cf_name' => $cf_name, 'cf_value' => $cf_value]
                );
                DB::commit();
                return 1;
            }catch (Exception $e) {

                DB::rollBack();
                return 0;
            }

        }
        else{
            $id = DB::table('config')->insertGetId(
                ['cf_name' => $cf_name, 'cf_value' => $cf_value]
            );
            return 1;
        }
    }
}